home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / BasicInternalFrameUI.java < prev    next >
Text File  |  1998-06-30  |  28KB  |  805 lines

  1. /*
  2.  * @(#)BasicInternalFrameUI.java    1.36 98/02/04
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.basic;
  22.  
  23. import java.awt.*;
  24. import java.awt.event.*;
  25. import com.sun.java.swing.*;
  26. import com.sun.java.swing.border.*;
  27. import com.sun.java.swing.plaf.*;
  28. import java.beans.*;
  29. import java.util.EventListener;
  30. import java.io.Serializable;
  31.  
  32.  
  33. /**
  34.  * A basic L&F implementation of JInternalFrame.  
  35.  * <p>
  36.  * Warning: serialized objects of this class will not be compatible with
  37.  * future swing releases.  The current serialization support is appropriate
  38.  * for short term storage or RMI between Swing1.0 applications.  It will
  39.  * not be possible to load serialized Swing1.0 objects with future releases
  40.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  41.  * baseline for the serialized form of Swing objects.
  42.  *
  43.  * @version 1.36 02/04/98
  44.  * @author David Kloba
  45.  */
  46. public class BasicInternalFrameUI extends InternalFrameUI 
  47.     implements LayoutManager, PropertyChangeListener, Serializable,
  48.                MouseListener
  49. {
  50.     protected JInternalFrame frame;
  51.     protected EventListener borderListener;
  52.     protected JComponent northPane;
  53.     protected JComponent southPane;
  54.     protected JComponent westPane;
  55.     protected JComponent eastPane;
  56.  
  57.     protected static DesktopManager sharedDesktopManager;
  58.  
  59. /////////////////////////////////////////////////////////////////////////////
  60. // ComponentUI Interface Implementation methods
  61. /////////////////////////////////////////////////////////////////////////////
  62.     public static ComponentUI createUI(JComponent b)    {
  63.         return new BasicInternalFrameUI((JInternalFrame)b);
  64.     }
  65.  
  66.     public BasicInternalFrameUI(JInternalFrame b)   {
  67.     }
  68.             
  69.     public void installUI(JComponent c)   {
  70.  
  71.         frame = (JInternalFrame)c;        
  72.     frame.add(frame.getRootPane(), "Center");
  73.  
  74.     installDefaults(frame);
  75.  
  76.         borderListener = createBorderListener(frame);
  77.  
  78.     frame.addPropertyChangeListener(this);
  79.         frame.setLayout(this);         
  80.  
  81.     setNorthPane(createNorthPane(frame));
  82.     setSouthPane(createSouthPane(frame));
  83.     setEastPane(createEastPane(frame));
  84.     setWestPane(createWestPane(frame));
  85.  
  86. //        if(frame.getContentPane() == null) {
  87. //            frame.setContentPane(createContentPane(frame));
  88. //        } else {
  89. ////            installMouseHandlers((JComponent)frame.getContentPane());
  90. //        }
  91.         installMouseHandlers(frame);
  92.     
  93.     frame.setOpaque(true);
  94.     frame.setMinimumSize(new Dimension(120, 24));
  95.     }   
  96.  
  97.     public void uninstallUI(JComponent c) {
  98.         if(c != frame)
  99.             throw new IllegalComponentStateException(
  100.                 this + " was asked to deinstall() " 
  101.                 + c + " when it only knows about " 
  102.                 + frame + "."); 
  103.                 
  104.     uninstallDefaults(frame);
  105.  
  106.     frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));    
  107.  
  108.     setNorthPane(null);
  109.     setSouthPane(null);
  110.     setEastPane(null);
  111.     setWestPane(null);
  112.         frame.setLayout(null);
  113. //        deinstallMouseHandlers((JComponent)frame.getContentPane());
  114.         deinstallMouseHandlers(frame);
  115.         borderListener = null;
  116.         frame.removePropertyChangeListener(this);
  117.         frame.remove(frame.getRootPane());    
  118.         frame = null;
  119.     }
  120.     
  121.     protected void installDefaults(JInternalFrame frame) {
  122.     Icon frameIcon = frame.getFrameIcon();
  123.         if (frameIcon == null || frameIcon instanceof UIResource) {
  124.             frame.setFrameIcon(UIManager.getIcon("InternalFrame.icon"));
  125.         }
  126.     
  127.     LookAndFeel.installBorder(frame, "InternalFrame.border");
  128.     }
  129.  
  130.     protected void uninstallDefaults(JInternalFrame frame) {
  131.     Icon frameIcon = frame.getFrameIcon();
  132.         if (frameIcon instanceof UIResource) {
  133.             frame.setFrameIcon(null);
  134.         }
  135.     LookAndFeel.uninstallBorder(frame);
  136.     }
  137.  
  138.     public Dimension getPreferredSize(JComponent x)    {
  139.     if((JComponent)frame == x)
  140.         return frame.getLayout().preferredLayoutSize(x);
  141.         return new Dimension(100, 100);
  142.     }
  143.     
  144.     public Dimension getMinimumSize(JComponent x)  {
  145.     if((JComponent)frame == x)
  146.         return frame.getLayout().minimumLayoutSize(x);
  147.         return new Dimension(0, 0);
  148.     }
  149.     
  150.     public Dimension getMaximumSize(JComponent x) {
  151.         return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
  152.     }
  153.     
  154.  
  155.     /** Detects changes in state from the JInternalFrame and handles actions.*/
  156.     public void propertyChange(PropertyChangeEvent evt) {
  157.         String prop = (String)evt.getPropertyName();
  158.         JInternalFrame f = (JInternalFrame)evt.getSource();
  159.     Object newValue = evt.getNewValue();
  160.     Object oldValue = evt.getOldValue();
  161.     // ASSERT(frame == f) - This should always be true
  162.  
  163.         if(JInternalFrame.ROOT_PANE_PROPERTY.equals(prop)) {
  164.         if(oldValue != null)
  165.         frame.remove((Component)oldValue);
  166.         if(newValue != null)
  167.         frame.add((Component)newValue);
  168.     /// Handle the action events from the Frame
  169.     } else if(JInternalFrame.IS_CLOSED_PROPERTY.equals(prop)) {
  170.         if(newValue == Boolean.TRUE)
  171.             closeFrame(f);
  172.     } else if(JInternalFrame.IS_MAXIMUM_PROPERTY.equals(prop)) {
  173.         if(newValue == Boolean.TRUE)
  174.         maximizeFrame(f);
  175.         else
  176.             minimizeFrame(f);
  177.     } else if(JInternalFrame.IS_ICON_PROPERTY.equals(prop)) {
  178.         if(newValue == Boolean.TRUE)
  179.         iconifyFrame(f);
  180.         else
  181.             deiconifyFrame(f);
  182.     } else if(JInternalFrame.IS_SELECTED_PROPERTY.equals(prop)) {
  183.         if(newValue == Boolean.TRUE
  184.                 && oldValue == Boolean.FALSE) {
  185.         activateFrame(f);
  186.         } else if(newValue == Boolean.FALSE
  187.                 && oldValue == Boolean.TRUE) {
  188.         deactivateFrame(f);
  189.         }
  190.     }
  191.     }
  192.             
  193.     /** Adds necessary mouseHandlers to currentPane and adds it to frame.
  194.       * Reverse process for the newPane. 
  195.       */
  196.     protected void replacePane(JComponent currentPane, JComponent newPane) {
  197.         if(currentPane != null) {
  198.             deinstallMouseHandlers(currentPane);
  199.             frame.remove(currentPane);
  200.         }
  201.         if(newPane != null) {
  202.            frame.add(newPane);
  203.            installMouseHandlers(newPane);
  204.         }
  205.     }
  206.  
  207.     protected void deinstallMouseHandlers(JComponent c) {
  208.         if(c != null) {
  209.             if(borderListener instanceof MouseListener)
  210.                 c.removeMouseListener((MouseListener)borderListener);
  211.             if(borderListener instanceof MouseMotionListener)
  212.                 c.removeMouseMotionListener((MouseMotionListener)borderListener);
  213.         }
  214.     }
  215.   
  216.     protected void installMouseHandlers(JComponent c) {
  217.         if(c != null) {
  218.             if(borderListener instanceof MouseListener)
  219.                 c.addMouseListener((MouseListener)borderListener);
  220.             if(borderListener instanceof MouseMotionListener)
  221.                 c.addMouseMotionListener((MouseMotionListener)borderListener);
  222.         }
  223.     }
  224.     
  225.     protected JComponent createNorthPane(JInternalFrame w) {
  226.         return new BasicInternalFrameTitlePane(w);
  227.     }
  228.  
  229.     protected JComponent createSouthPane(JInternalFrame w) {
  230.     return null;
  231.     }
  232.  
  233.     protected JComponent createWestPane(JInternalFrame w) {
  234.         return null;
  235.     }
  236.  
  237.     protected JComponent createEastPane(JInternalFrame w) {
  238.         return null;
  239.     }
  240.  
  241. //    protected JComponent createContentPane(JInternalFrame w) {
  242. //    JComponent p = new JComponent();
  243. //    p.setLayout(new BorderLayout());
  244. //        return p;
  245. //    }
  246.  
  247.     protected EventListener createBorderListener(JInternalFrame w) {
  248.         return new BorderListener();
  249.     }
  250.  
  251.     public JComponent getNorthPane() {
  252.         return northPane;
  253.     }
  254.  
  255.     public void setNorthPane(JComponent c) {
  256.         replacePane(northPane, c);
  257.         northPane = c;
  258.     }
  259.  
  260.     public JComponent getSouthPane() {
  261.         return southPane;
  262.     }
  263.  
  264.     public void setSouthPane(JComponent c) {
  265. //        replacePane(southPane, c);
  266.         southPane = c;
  267.     }
  268.  
  269.     public JComponent getWestPane() {
  270.         return westPane;
  271.     }
  272.  
  273.     public void setWestPane(JComponent c) {
  274. //        replacePane(westPane, c);
  275.         westPane = c;
  276.     }
  277.  
  278.     public JComponent getEastPane() {
  279.         return eastPane;
  280.     }
  281.  
  282.     public void setEastPane(JComponent c) {
  283. //        replacePane(eastPane, c);
  284.         eastPane = c;
  285.     }
  286.  
  287.     public void addLayoutComponent(String name, Component c) {}
  288.     public void removeLayoutComponent(Component c) {}    
  289.     public Dimension preferredLayoutSize(Container c)  {
  290.     Dimension result;
  291.     Insets i = frame.getInsets();
  292.     
  293.     result = frame.getRootPane().getPreferredSize();
  294.     result.width += i.left + i.right;
  295.     result.height += i.top + i.bottom;
  296.  
  297.         if(getNorthPane() != null) {
  298.         Dimension d = getNorthPane().getPreferredSize();
  299.         result.width = Math.max(d.width, result.width);
  300.             result.height += d.height;
  301.     }
  302.  
  303.         if(getSouthPane() != null) {
  304.         Dimension d = getSouthPane().getPreferredSize();
  305.         result.width = Math.max(d.width, result.width);
  306.             result.height += d.height;
  307.     }
  308.  
  309.         if(getEastPane() != null) {
  310.         Dimension d = getEastPane().getPreferredSize();
  311.             result.width += d.width;
  312.         result.height = Math.max(d.height, result.height);
  313.     }
  314.  
  315.         if(getWestPane() != null) {
  316.         Dimension d = getWestPane().getPreferredSize();
  317.             result.width += d.width;
  318.         result.height = Math.max(d.height, result.height);
  319.     }
  320.  
  321.     return result;
  322.     }
  323.     
  324.     public Dimension minimumLayoutSize(Container c) {
  325.     Dimension result;
  326.     Insets i = frame.getInsets();
  327.     
  328.     result = frame.getRootPane().getMinimumSize();
  329.     result.width += i.left + i.right;
  330.     result.height += i.top + i.bottom;
  331.  
  332.         if(getNorthPane() != null) {
  333.         Dimension d = getNorthPane().getMinimumSize();
  334.         result.width = Math.max(d.width, result.width);
  335.             result.height += d.height;
  336.     }
  337.  
  338.         if(getSouthPane() != null) {
  339.         Dimension d = getSouthPane().getMinimumSize();
  340.         result.width = Math.max(d.width, result.width);
  341.             result.height += d.height;
  342.     }
  343.  
  344.         if(getEastPane() != null) {
  345.         Dimension d = getEastPane().getMinimumSize();
  346.             result.width += d.width;
  347.         result.height = Math.max(d.height, result.height);
  348.     }
  349.  
  350.         if(getWestPane() != null) {
  351.         Dimension d = getWestPane().getMinimumSize();
  352.             result.width += d.width;
  353.         result.height = Math.max(d.height, result.height);
  354.     }
  355.  
  356.     return result;
  357.     }
  358.     
  359.     public void layoutContainer(Container c) {
  360.         Insets i = frame.getInsets();
  361.         int cx, cy, cw, ch;
  362.         
  363.         cx = i.left;
  364.         cy = i.top;
  365.         cw = frame.getWidth() - i.left - i.right;
  366.         ch = frame.getHeight() - i.top - i.bottom;
  367.         
  368.         if(getNorthPane() != null) {
  369.             Dimension size = getNorthPane().getPreferredSize();
  370.             getNorthPane().setBounds(cx, cy, cw, size.height);
  371.             cy += size.height;
  372.             ch -= size.height;
  373.         }
  374.  
  375.         if(getSouthPane() != null) {
  376.             Dimension size = getSouthPane().getPreferredSize();
  377.             getSouthPane().setBounds(cx, frame.getHeight() 
  378.                                                 - i.bottom - size.height, 
  379.                                                 cw, size.height);
  380.             ch -= size.height;
  381.         }
  382.  
  383.         if(getWestPane() != null) {
  384.             Dimension size = getWestPane().getPreferredSize();
  385.             getWestPane().setBounds(cx, cy, size.width, ch);
  386.             cw -= size.width;
  387.             cx += size.width;           
  388.         }
  389.  
  390.         if(getEastPane() != null) {
  391.             Dimension size = getEastPane().getPreferredSize();
  392.             getEastPane().setBounds(cw - size.width, cy, size.width, ch);
  393.             cw -= size.width;           
  394.         }
  395.         
  396.         if(frame.getRootPane() != null) {
  397.             frame.getRootPane().setBounds(cx, cy, cw, ch);
  398.         }
  399.     }
  400.  
  401. /// DesktopManager methods
  402.     /** Returns the proper DesktopManager. Calls getDesktopPane() to 
  403.       * find the JDesktop component and returns the desktopManager from
  404.       * it. If this fails, it will return a default DesktopManager that 
  405.       * should work in arbitrary parents.
  406.       */
  407.     protected DesktopManager getDesktopManager() {
  408.     if(frame.getDesktopPane() != null 
  409.         && frame.getDesktopPane().getDesktopManager() != null)
  410.         return frame.getDesktopPane().getDesktopManager();
  411.     if(sharedDesktopManager == null)
  412.         sharedDesktopManager = new DefaultDesktopManager();
  413.     return sharedDesktopManager;    
  414.     }
  415.  
  416.     /** This method is called when the user wants to close the frame.
  417.       * This action is delegated to the desktopManager.
  418.       */
  419.     protected void closeFrame(JInternalFrame f) {    
  420.     getDesktopManager().closeFrame(f);
  421.     }
  422.     /** This method is called when the user wants to maximize the frame.
  423.       * This action is delegated to the desktopManager.
  424.       */
  425.     protected void maximizeFrame(JInternalFrame f) {    
  426.     getDesktopManager().maximizeFrame(f);
  427.     }
  428.     /** This method is called when the user wants to minimize the frame.
  429.       * This action is delegated to the desktopManager.
  430.       */
  431.     protected void minimizeFrame(JInternalFrame f) {
  432.     getDesktopManager().minimizeFrame(f);
  433.     }
  434.     /** This method is called when the user wants to iconify the frame.
  435.       * This action is delegated to the desktopManager.
  436.       */
  437.     protected void iconifyFrame(JInternalFrame f) {
  438.     getDesktopManager().iconifyFrame(f);
  439.     }
  440.     /** This method is called when the user wants to deiconify the frame.
  441.       * This action is delegated to the desktopManager.
  442.       */
  443.     protected void deiconifyFrame(JInternalFrame f) {
  444.     getDesktopManager().deiconifyFrame(f);
  445.     }
  446.     /** This method is called when the frame becomes selected.
  447.       * This action is delegated to the desktopManager.
  448.       */
  449.     protected void activateFrame(JInternalFrame f) {
  450.     getDesktopManager().activateFrame(f);
  451.     }
  452.     /** This method is called when the frame is no longer selected.
  453.       * This action is delegated to the desktopManager.
  454.       */
  455.     protected void deactivateFrame(JInternalFrame f) {
  456.     getDesktopManager().deactivateFrame(f);
  457.     }
  458.  
  459.     /**
  460.      * Forward mouse events on to border -- used when the frame is
  461.      * inactive to reactivate it when the mouse is clicked over it.
  462.      */
  463.     public void mousePressed(MouseEvent e) {
  464.         ((BorderListener)borderListener).mousePressed(e);
  465.     }
  466.  
  467.     /*
  468.      * Unused mouse event handlers.
  469.      */
  470.     public void mouseClicked(MouseEvent e) {}
  471.     public void mouseReleased(MouseEvent e) {}
  472.     public void mouseEntered(MouseEvent e) {}
  473.     public void mouseExited(MouseEvent e) {}
  474.  
  475.     /////////////////////////////////////////////////////////////////////////
  476.     /// Border Listener Class
  477.     /////////////////////////////////////////////////////////////////////////        
  478.     /**
  479.      * Listens for border adjustments.
  480.      * <p>
  481.      * Warning: serialized objects of this class will not be compatible with
  482.      * future swing releases.  The current serialization support is appropriate
  483.      * for short term storage or RMI between Swing1.0 applications.  It will
  484.      * not be possible to load serialized Swing1.0 objects with future releases
  485.      * of Swing.  The JDK1.2 release of Swing will be the compatibility
  486.      * baseline for the serialized form of Swing objects.
  487.      */
  488.     protected class BorderListener extends MouseAdapter
  489.         implements MouseMotionListener, SwingConstants, Serializable
  490.     {
  491.     // _x & _y are the mousePressed location in absolute coordinate system
  492.         int _x, _y;
  493.     // __x & __y are the mousePressed location in source view's coordinate system
  494.     int __x, __y;
  495.         Rectangle startingBounds;
  496.         int resizeDir;
  497.         
  498.         protected final int RESIZE_NONE  = 0;
  499.                 
  500.         int resizeCornerSize = 16;
  501.         
  502.         public void mouseReleased(MouseEvent e) {
  503.         if(resizeDir == RESIZE_NONE)
  504.             getDesktopManager().endDraggingFrame(frame);    
  505.         else
  506.             getDesktopManager().endResizingFrame(frame);    
  507.             _x = 0;
  508.             _y = 0;
  509.             __x = 0;
  510.             __y = 0;
  511.             startingBounds = null;
  512.             resizeDir = RESIZE_NONE;
  513.         }
  514.                 
  515.         public void mousePressed(MouseEvent e) {
  516.             Point p = SwingUtilities.convertPoint((Component)e.getSource(), 
  517.                         e.getX(), e.getY(), null);
  518.             __x = e.getX();
  519.             __y = e.getY();
  520.             _x = p.x;
  521.             _y = p.y;
  522.             startingBounds = frame.getBounds();
  523.  
  524.             if(!frame.isSelected()) {
  525.                 try { frame.setSelected(true); } catch (PropertyVetoException e1) { }
  526.             }
  527.  
  528.             if(e.getClickCount() > 1 && e.getSource() == getNorthPane()) {
  529.         if(frame.isIconifiable() && frame.isIcon()) {
  530.                     try { frame.setIcon(false); } catch (PropertyVetoException e2) { }
  531.         } else if(frame.isMaximizable()) {
  532.                     if(!frame.isMaximum())
  533.                         try { frame.setMaximum(true); } catch (PropertyVetoException e2) { }
  534.                     else
  535.                         try { frame.setMaximum(false); } catch (PropertyVetoException e3) { }
  536.         } 
  537.             }
  538.  
  539.             if(!frame.isResizable() || e.getSource() == getNorthPane()) {
  540.                 resizeDir = RESIZE_NONE;
  541.         getDesktopManager().beginDraggingFrame(frame);
  542.                 return;
  543.             }       
  544.  
  545.             if(e.getSource() == frame) {
  546.                 Insets i = frame.getInsets();
  547.                 if(e.getX() <= i.left) {
  548.                     if(e.getY() < resizeCornerSize + i.top)
  549.                         resizeDir = NORTH_WEST;
  550.                     else if(e.getY() > frame.getHeight() 
  551.                     - resizeCornerSize - i.bottom)
  552.                         resizeDir = SOUTH_WEST;
  553.                     else                
  554.                         resizeDir = WEST;
  555.                 } else if(e.getX() >= frame.getWidth() - i.right) {
  556.                     if(e.getY() < resizeCornerSize + i.top)
  557.                         resizeDir = NORTH_EAST;
  558.                     else if(e.getY() > frame.getHeight() 
  559.                 - resizeCornerSize - i.bottom)
  560.                         resizeDir = SOUTH_EAST;
  561.                     else                
  562.                         resizeDir = EAST;
  563.                 } else if(e.getY() <= i.top) {
  564.                     if(e.getX() < resizeCornerSize + i.left)
  565.                         resizeDir = NORTH_WEST;
  566.                     else if(e.getX() > frame.getWidth() 
  567.                 - resizeCornerSize - i.right)
  568.                         resizeDir = NORTH_EAST;
  569.                     else                
  570.                         resizeDir = NORTH;
  571.                 } else if(e.getY() >= frame.getHeight() - i.bottom) {
  572.                     if(e.getX() < resizeCornerSize + i.left)
  573.                         resizeDir = SOUTH_WEST;
  574.                     else if(e.getX() > frame.getWidth() 
  575.                 - resizeCornerSize - i.right)
  576.                         resizeDir = SOUTH_EAST;
  577.                     else                
  578.                         resizeDir = SOUTH;
  579.                 } 
  580.             getDesktopManager().beginResizingFrame(frame, resizeDir);
  581.                 return;
  582.             }
  583.         }
  584.  
  585.         public void mouseDragged(MouseEvent e) {   
  586.  
  587.         if ( startingBounds == null ) {
  588.           // (STEVE) Yucky work around for bug ID 4106552
  589.          return;
  590.         }
  591.                                      
  592.             Point p; 
  593.         int newX, newY, newW, newH;
  594.             int deltaX;
  595.             int deltaY;
  596.         Dimension min;
  597.         Dimension max;
  598.             p = SwingUtilities.convertPoint((Component)e.getSource(), 
  599.                                         e.getX(), e.getY(), null);
  600.         
  601.             // Handle a MOVE 
  602.             if(e.getSource() == getNorthPane()) {
  603.                 if (frame.isMaximum()) {
  604.                     return;  // don't allow moving of maximized frames.
  605.                 }
  606.         Insets i = frame.getInsets();
  607.         int pWidth, pHeight;
  608.         Dimension s = frame.getParent().getSize();
  609.         pWidth = s.width;
  610.         pHeight = s.height;
  611.  
  612.  
  613.             newX = startingBounds.x - (_x - p.x);
  614.             newY = startingBounds.y - (_y - p.y);
  615.         // Make sure we stay in-bounds
  616.         if(newX + i.left <= -__x)
  617.             newX = -__x - i.left;
  618.         if(newY + i.top <= -__y)
  619.             newY = -__y - i.top;
  620.         if(newX + __x + i.right > pWidth)
  621.             newX = pWidth - __x - i.right;
  622.         if(newY + __y + i.bottom > pHeight)
  623.             newY =  pHeight - __y - i.bottom;
  624.  
  625.         getDesktopManager().dragFrame(frame, newX, newY);
  626.                 return;
  627.             }
  628.  
  629.             if(!frame.isResizable()) {
  630.                 return;
  631.             }
  632.  
  633.         min = frame.getMinimumSize();
  634.         max = frame.getMaximumSize();
  635.         
  636.             deltaX = _x - p.x;
  637.             deltaY = _y - p.y;
  638.  
  639.         newX = frame.getX();
  640.         newY = frame.getY();
  641.         newW = frame.getWidth();
  642.         newH = frame.getHeight();
  643.  
  644.             switch(resizeDir) {
  645.             case RESIZE_NONE:
  646.                 return;
  647.             case NORTH:      
  648.         if(startingBounds.height + deltaY < min.height)
  649.             deltaY = -(startingBounds.height - min.height);
  650.         else if(startingBounds.height + deltaY > max.height)
  651.             deltaY = (startingBounds.height - min.height);
  652.  
  653.         newX = startingBounds.x;
  654.         newY = startingBounds.y - deltaY;
  655.         newW = startingBounds.width;
  656.         newH = startingBounds.height + deltaY;
  657.                 break;
  658.             case NORTH_EAST:     
  659.         if(startingBounds.height + deltaY < min.height)
  660.             deltaY = -(startingBounds.height - min.height);
  661.         else if(startingBounds.height + deltaY > max.height)
  662.             deltaY = (startingBounds.height - min.height);
  663.  
  664.         if(startingBounds.width - deltaX < min.width)
  665.             deltaX = (startingBounds.width - min.width);
  666.         else if(startingBounds.width - deltaX > max.width)
  667.             deltaX = -(startingBounds.width - min.width);
  668.  
  669.         newX = startingBounds.x;
  670.         newY = startingBounds.y - deltaY;
  671.         newW = startingBounds.width - deltaX;
  672.         newH = startingBounds.height + deltaY;
  673.                 break;
  674.             case EAST:      
  675.         if(startingBounds.width - deltaX < min.width)
  676.             deltaX = (startingBounds.width - min.width);
  677.         else if(startingBounds.width - deltaX > max.width)
  678.             deltaX = -(startingBounds.width - min.width);
  679.  
  680.         newW = startingBounds.width - deltaX;
  681.         newH = startingBounds.height;
  682.                 break;
  683.             case SOUTH_EAST:     
  684.         if(startingBounds.width - deltaX < min.width)
  685.             deltaX = (startingBounds.width - min.width);
  686.         else if(startingBounds.width - deltaX > max.width)
  687.             deltaX = -(startingBounds.width - min.width);
  688.  
  689.         if(startingBounds.height - deltaY < min.height)
  690.             deltaY = (startingBounds.height - min.height);
  691.         else if(startingBounds.height - deltaY > max.height)
  692.             deltaY = -(startingBounds.height - min.height);
  693.     
  694.         newW = startingBounds.width - deltaX;
  695.         newH = startingBounds.height - deltaY;
  696.                 break;
  697.             case SOUTH:      
  698.         if(startingBounds.height - deltaY < min.height)
  699.             deltaY = (startingBounds.height - min.height);
  700.         else if(startingBounds.height - deltaY > max.height)
  701.             deltaY = -(startingBounds.height - min.height);
  702.  
  703.          newW = startingBounds.width;
  704.         newH = startingBounds.height - deltaY;
  705.                 break;
  706.             case SOUTH_WEST:
  707.         if(startingBounds.height - deltaY < min.height)
  708.             deltaY = (startingBounds.height - min.height);
  709.         else if(startingBounds.height - deltaY > max.height)
  710.             deltaY = -(startingBounds.height - min.height);
  711.  
  712.         if(startingBounds.width + deltaX < min.width)
  713.             deltaX = -(startingBounds.width - min.width);
  714.         else if(startingBounds.width + deltaX > max.width)
  715.             deltaX = (startingBounds.width - min.width);
  716.  
  717.         newX = startingBounds.x - deltaX;
  718.         newY = startingBounds.y;
  719.         newW = startingBounds.width + deltaX;
  720.         newH = startingBounds.height - deltaY;
  721.                 break;
  722.             case WEST:      
  723.         if(startingBounds.width + deltaX < min.width)
  724.             deltaX = -(startingBounds.width - min.width);
  725.         else if(startingBounds.width + deltaX > max.width)
  726.             deltaX = (startingBounds.width - min.width);
  727.  
  728.         newX = startingBounds.x - deltaX;
  729.         newY = startingBounds.y;
  730.         newW = startingBounds.width + deltaX;
  731.         newH = startingBounds.height;
  732.                 break;
  733.             case NORTH_WEST:     
  734.         if(startingBounds.width + deltaX < min.width)
  735.             deltaX = -(startingBounds.width - min.width);
  736.         else if(startingBounds.width + deltaX > max.width)
  737.             deltaX = (startingBounds.width - min.width);
  738.  
  739.         if(startingBounds.height + deltaY < min.height)
  740.             deltaY = -(startingBounds.height - min.height);
  741.         else if(startingBounds.height + deltaY > max.height)
  742.             deltaY = (startingBounds.height - min.height);
  743.  
  744.         newX = startingBounds.x - deltaX;
  745.         newY = startingBounds.y - deltaY;
  746.         newW = startingBounds.width + deltaX;
  747.         newH = startingBounds.height + deltaY;
  748.                 break;
  749.             default:
  750.                 return;
  751.             }
  752.  
  753.         getDesktopManager().resizeFrame(frame, newX, newY, newW, newH);
  754.     }
  755.  
  756.         public void mouseMoved(MouseEvent e)    {
  757.  
  758.         if(!frame.isResizable())
  759.         return;
  760.         
  761.             if(e.getSource() == frame) {
  762.                 Insets i = frame.getInsets();
  763.                 if(e.getX() <= i.left) {
  764.                     if(e.getY() < resizeCornerSize + i.top)
  765.             frame.setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
  766.                     else if(e.getY() > frame.getHeight() - resizeCornerSize - i.bottom)
  767.             frame.setCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR));
  768.                     else                
  769.             frame.setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
  770.                 } else if(e.getX() >= frame.getWidth() - i.right) {
  771.                     if(e.getY() < resizeCornerSize + i.top)
  772.             frame.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
  773.                     else if(e.getY() > frame.getHeight() - resizeCornerSize - i.bottom)
  774.             frame.setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
  775.                     else                
  776.             frame.setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
  777.                 } else if(e.getY() <= i.top) {
  778.                     if(e.getX() < resizeCornerSize + i.left)
  779.             frame.setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
  780.                     else if(e.getX() > frame.getWidth() - resizeCornerSize - i.right)
  781.             frame.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
  782.                     else                
  783.             frame.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
  784.                 } else if(e.getY() >= frame.getHeight() - i.bottom) {
  785.                     if(e.getX() < resizeCornerSize + i.left)
  786.             frame.setCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR));
  787.                     else if(e.getX() > frame.getWidth() - resizeCornerSize - i.right)
  788.             frame.setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
  789.                     else                
  790.             frame.setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
  791.                 }
  792.         return;
  793.             }
  794.  
  795.         frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));    
  796.     }         
  797.  
  798.         public void mouseExited(MouseEvent e)    {
  799.         frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));    
  800.     }
  801.     };    /// End BorderListener Class
  802.  
  803. }   /// End BasicInternalFrameUI Class
  804.  
  805.